package org.android.tools;

import java.util.Hashtable;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;

public class Product implements KvmSerializable{

    public boolean actual;
    public String brand;
    public String data;
    public String howPacket;
	public Integer idproduct;
	public String info;
	public String name;
	public Integer plus;
    public Double price;
    
    public Product() {}
	
    public Product(String name, Double price, String data, boolean actual) {
        this.name = name;
        this.price = price;
        this.data = data;
        this.actual = actual;
    }
    
    public Product(String name, Double price, String data, String info, String howPacket, String brand, Integer plus, boolean actual) {
       this.name = name;
       this.price = price;
       this.data = data;
       this.info = info;
       this.howPacket = howPacket;
       this.brand = brand;
       this.plus = plus;
       this.actual = actual;
    }
    
    public Object getProperty(int arg0) {
		// TODO Auto-generated method stub
		switch(arg0)
        {
        case 0:
        	return actual;
        case 1:
        	return brand;
        case 2:
            return data;
        case 3:
            return howPacket;
        case 4:
        	return idproduct;
        case 5:
        	return info;
        case 6:
        	return name;
        case 7:
        	return plus;
        case 8:
        	return price;
        }
		return null;
	}

	public int getPropertyCount() {
		// TODO Auto-generated method stub
		return 9;
	}

	public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
		// TODO Auto-generated method stub
		switch(arg0)
        {
        case 0:
        	arg2.type = PropertyInfo.BOOLEAN_CLASS;
        	arg2.name = "actual";
        	break;
        case 1:
        	arg2.type = PropertyInfo.STRING_CLASS;
        	arg2.name = "brand";
            break;
        case 2:
            arg2.type = PropertyInfo.STRING_CLASS;
            arg2.name = "data";
            break;
        case 3:
        	arg2.type = PropertyInfo.STRING_CLASS;
        	arg2.name = "howPacket";
            break;
        case 4:
        	arg2.type = PropertyInfo.INTEGER_CLASS;
        	arg2.name = "idproduct";
            break;
        case 5:
        	arg2.type = PropertyInfo.STRING_CLASS;
        	arg2.name = "info";
        	break;
        case 6:
        	arg2.type = PropertyInfo.STRING_CLASS;
        	arg2.name = "name";
        	break;
        case 7:
        	arg2.type = PropertyInfo.INTEGER_CLASS;
        	arg2.name = "plus";
        	break;
        case 8:
        	arg2.type = Double.class;
        	arg2.name = "price";
        	break;
        default:break;
        }
	}

	public void setProperty(int arg0, Object arg1) {
		// TODO Auto-generated method stub
		switch(arg0)
        {
        case 0:
            actual = Boolean.parseBoolean(arg1.toString());
            break;
        case 1:
            brand = arg1.toString();
            break;
        case 2:
            data = arg1.toString();
            break;
        case 3:
            howPacket = arg1.toString();
            break;
        case 4:
            idproduct = Integer.parseInt(arg1.toString());
            break;
        case 5:
            info = arg1.toString();
            break;
        case 6:
            name = arg1.toString();
            break;
        case 7:
            plus = Integer.parseInt((arg1.toString()));
            break;
        case 8:
        	price = Double.parseDouble(arg1.toString());
        	break;
        default:
            break;
        }
	}
	
	public static Product parseProduct(SoapObject soap, int arg0)
	{
		SoapObject arg1 = (SoapObject) soap.getProperty(arg0);
		Product product = new Product();
		product.actual = Boolean.parseBoolean(arg1.getProperty(0).toString());
		product.brand = arg1.getProperty(1).toString();
		product.data = arg1.getProperty(2).toString();
		product.howPacket = arg1.getProperty(3).toString();
		product.idproduct = Integer.parseInt(arg1.getProperty(4).toString());
		product.info = arg1.getProperty(5).toString();
		product.name = arg1.getProperty(6).toString();
		product.plus = Integer.parseInt((arg1.getProperty(7).toString()));
		product.price = Double.parseDouble(arg1.getProperty(8).toString());
		return product;
	}
	
	public static Product[] parseProduct(SoapObject soap)
    {
		Product[] products = new Product[soap.getPropertyCount()];
        for (int i = 0; i < products.length; i++) {
            SoapObject pii = (SoapObject)soap.getProperty(i);
            Product product = new Product();
    		product.actual = Boolean.parseBoolean(pii.getProperty(0).toString());
    		product.brand = pii.getProperty(1).toString();
    		product.data = pii.getProperty(2).toString();
    		product.howPacket = pii.getProperty(3).toString();
    		product.idproduct = Integer.parseInt(pii.getProperty(4).toString());
    		product.info = pii.getProperty(5).toString();
    		product.name = pii.getProperty(6).toString();
    		product.plus = Integer.parseInt((pii.getProperty(7).toString()));
    		product.price = Double.parseDouble(pii.getProperty(8).toString());
            products[i] = product;
        }
        return products;
    }
}
